package com.zh.springcloud.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @ClassName TopicRabbitConfig
 * @date: 2021.08.23 09:52
 * @Author: zhanghang
 */
@Configuration
public class TopicRabbitConfig1 {
	// 正常的topic 队列
	public static final String TEST_TOPIC_EXCHANGE_NAME = "test_topic_exchange_name1";
	public static final String TEST_TOPIC_QUEUE_NAME = "test_topic_queue_name1";
	public static final String TEST_TOPIC_ROUTING_NAME = "test_topic_routing_name1";


	// 正常的队列
	@Bean
	public Queue createTopicQueue1(){

		return new Queue(TEST_TOPIC_QUEUE_NAME,true,false,false);
	}

	@Bean
	public CustomExchange createTopicExchange1(){
		Map<String, Object> args = new HashMap<String, Object>();
		args.put("x-delayed-type", "direct");
		// 参数说明：
		// name:    交换机名称
		// durable： 是否持久化
		// autoDelete： 是否自动删除
		return new CustomExchange(TEST_TOPIC_EXCHANGE_NAME,"x-delayed-message",true,false,args);
	}

	@Bean
	public Binding createTopicBinding1(){
		return BindingBuilder.bind(createTopicQueue1()).to(createTopicExchange1()).with(TEST_TOPIC_ROUTING_NAME).noargs();
	}



}
